<template>
  <svg :class="svgClass" aria-hidden="true" v-on="$attrs">
    <use :href="iconName" />
  </svg>
</template>

<script setup lang="ts">
import { computed } from "vue";
const props = defineProps({
  // 图标名称
  iconClass: {
    type: String,
    required: true,
  },
  // 图标样式class名称
  className: {
    type: String,
    default: "",
  },
});

const svgClass = computed(() => {
  if (props.className) {
    return `svg-icon ${props.className}`;
  }
  return "svg-icon";
});

const iconName = computed(() => {
  return `#icon-${props.iconClass}`;
});
</script>

<style scoped>
.svg-icon {
  width: 1em;
  height: 1em;
  fill: currentColor;
  overflow: hidden;
}
</style>
